// pages/user/tousu/tousu.js
Page({
  data: {
    multiArray: [[], [], []],
    objectMultiArray: [],
    multiIndex: [0, 0, 0],
    bsxl: 0,  // 办事效率的评价
    fwtd: 0,  // 服务态度的评价
    zhmyd: 0,  // 综合满意度的评价
    rjpj: 0,  // 软件评价的评价
    zhpj: 0,  // 综合评价的评价
  },
  onLoad: function () {
    var that = this;
    wx.request({
      url: 'https://markc1d.top:3000/api/data/worker',
      success: function (res) {
        console.log('收到数据：', res.data);
        let workers = res.data.map(item => ({name: item.worker, dept: [], product: []}));
        that.setData({
          objectMultiArray: workers
        });
        that.updateMultiArray();
      }
    });
  },
  MultiChange: function (e) {
    this.setData({
      multiIndex: e.detail.value
    })
  },
  MultiColumnChange: function (e) {
    let data = {
      multiArray: this.data.multiArray,
      multiIndex: this.data.multiIndex
    };
    data.multiIndex[e.detail.column] = e.detail.value;
    this.updateMultiArray(data);
  },
  updateMultiArray: function (data) {
    if (!data) {
      data = {
        multiArray: this.data.multiArray,
        multiIndex: this.data.multiIndex
      };
    }
    for (var i = 0; i < this.data.objectMultiArray.length; i++) {
      data.multiArray[0].push(this.data.objectMultiArray[i].name);
    }
    this.setData(data);
  },
  onChangeBsxl(event) {
    this.setData({
      bsxl: event.detail,
    });
  },
  onChangeFwtd(event) {
    this.setData({
      fwtd: event.detail,
    });
  },
  onChangeZhmyd(event) {
    this.setData({
      zhmyd: event.detail,
    });
  },
  onChangeRjpj(event) {
    this.setData({
      rjpj: event.detail,
    });
  },
  onChangeZhpj(event) {
    this.setData({
      zhpj: event.detail,
    });
  },
  submitReview() {
    wx.request({
      url: 'https://markc1d.top:3000/api/data/evaluate',  // 你的服务器 API
      method: 'POST',
      data: {
        worker: this.data.multiArray[0][this.data.multiIndex[0]],  // 工作人员名字
        bsxl: this.data.bsxl,  // 办事效率的评价
        fwtd: this.data.fwtd,  // 服务态度的评价
        zhmyd: this.data.zhmyd,  // 综合满意度的评价
        rjpj: this.data.rjpj,  // 软件评价的评价
        zhpj: this.data.zhpj,  // 综合评价的评价
      },
      success(res) {
        console.log(res.data);
      }
    });
  },
});
